A buffer holding binary data. More...
Public Member Functions | |
Buffer () | |
Buffer (unsigned long long size) | |
Buffer (unsigned char *data, unsigned long long size) | |
Buffer (const Buffer &other) | |
Buffer (Buffer &&other) | |
~Buffer () | |
unsigned char * | getData () const |
unsigned long long | getSize () const |
bool | empty () const |
unsigned char & | front () |
unsigned char & | back () |
void | clear () |
void | resize (unsigned long long size) |
unsigned char & | append (unsigned char value) |
unsigned char & | append (unsigned char value) |
BufferInfo | relinquishDataOwnership () |
unsigned char & | operator[] (unsigned long long index) |
const unsigned char & | operator[] (unsigned long long index) const |
Buffer & | operator= (const Buffer &other) |
Buffer & | operator= (Buffer &&other) |
template<typename T > | |
Buffer (const std::vector< T > &vec) | |
A buffer holding binary data.
The Buffer class owns its memory, and is hard coded to handle binary data shaped as unsigned char. It is meant to manage all memory and operations in the DLL itself, meaning that passing one from user space to dll space is safe. This class will be the basis to safely exchange data with components. It avoids having to play with vectors that can be unsafe due to their build time template parameters.
If you need something else than unsigned char, take a look at the BufferCast template class. Its purpose is to use this class, with an API casting for you. For data that doesn't need to be copied, BufferView can be the answer as it is only meant to offer a bridge to the data.
nkMemory::Buffer::Buffer | ( | ) |
Default constructor. The buffer will be empty.
nkMemory::Buffer::Buffer | ( | unsigned long long | size | ) |
Size constructor. Will allocate the size requested within the buffer. Memory will be 0-cleared.
size | The size of the buffer to create. As this buffer is binary, size is in bytes. |
nkMemory::Buffer::Buffer | ( | unsigned char * | data, |
unsigned long long | size | ||
) |
Data constructor. Will copy the data into its internal memory.
data | Pointer to the data to copy. |
size | The size of the data to copy, in bytes. |
nkMemory::Buffer::Buffer | ( | const Buffer & | other | ) |
Copy constructor. Will duplicate the data.
other | The buffer to copy. |
nkMemory::Buffer::Buffer | ( | Buffer && | other | ) |
Move constructor. Data will be moved into the buffer being constructed.
other | The buffer to move. |
nkMemory::Buffer::~Buffer | ( | ) |
Destructor. The destructor frees the memory, invalidating all potential pointers to it.
nkMemory::Buffer::Buffer | ( | const std::vector< T > & | vec | ) |
Utility copy constructor with vectors.
vec | The vector to copy from. |
unsigned char* nkMemory::Buffer::getData | ( | ) | const |
unsigned long long nkMemory::Buffer::getSize | ( | ) | const |
bool nkMemory::Buffer::empty | ( | ) | const |
unsigned char& nkMemory::Buffer::front | ( | ) |
unsigned char& nkMemory::Buffer::back | ( | ) |
void nkMemory::Buffer::clear | ( | ) |
Clears the buffer, freeing its internal memory and resetting it to its empty state.
void nkMemory::Buffer::resize | ( | unsigned long long | size | ) |
Resizes the buffer for it to fit a given size. This will trigger a reallocation of the data. In the process, the buffer will copy its content to the new memory area.
size | The size to fit, in bytes. |
unsigned char& nkMemory::Buffer::append | ( | unsigned char | value | ) |
Appends a byte to the buffer. This will cause the buffer to reallocate and copy data around. Use it wisely.
value | The value of the byte to append. |
unsigned char& nkMemory::Buffer::append | ( | unsigned char | value | ) |
Appends a byte to the buffer. This will cause the buffer to reallocate and copy data around. Use it wisely.
value | The value of the byte to append. |
BufferInfo nkMemory::Buffer::relinquishDataOwnership | ( | ) |
Requests a buffer to abandon its ownership, leaving the management to the client using this function.
unsigned char& nkMemory::Buffer::operator[] | ( | unsigned long long | index | ) |
Indexing operator.
index | The index of the element to index in the memory. |
const unsigned char& nkMemory::Buffer::operator[] | ( | unsigned long long | index | ) | const |
Indexing operator, const versioned.
index | The index of the element to index in the memory. |
Copy assignment operator.
other | The buffer to copy. |
Move assignment operator.
other | The buffer to move. |